import React, { useEffect } from 'react';
import { connect, history } from 'umi';
import PageLoading from '@/components/PageLoading';

const mapDispatchToProps = (dispatch) => ({
  ssoLogin: (payload) =>
    dispatch({
      type: `global/ssoLogin`,
      payload,
    }),
});

export default connect(
  null,
  mapDispatchToProps,
)((props) => {
  const { ssoLogin, location } = props;

  useEffect(() => {
    ssoLogin({ token: location.query.token, main: location.query.main }).then(() => {
      history.push('/');
    });
  }, []);

  return <PageLoading />;
});
